﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Beaker100ml : BaseBrokenObj
{
    public Transform m_Funnel;
    public Animator m_WaterAnimator;
    public GameObject m_Water;

    public override void OnHandleTrigger(Transform camera, NoloDeviceType handleType)
    {
        base.OnHandleTrigger(camera, handleType);
        m_WaterAnimator.SetBool("take", true);
    }

    public override void OnReleseTrigger(NoloDeviceType handleType)
    {
        base.OnReleseTrigger(handleType);
        m_WaterAnimator.SetBool("take", false);
    }


    Vector3 towardPos;
    Vector3 lastPos;
    float speed;
    private void FixedUpdate()
    {
        if (Vector3.Distance(m_Funnel.position, transform.position) < 0.1f)
        {
            float z = transform.eulerAngles.z;
            Debug.LogWarning(z);
            if ((z < 180 && z > 90 && transform.position.x > m_Funnel.position.x) ||
            (z > 180 && z < 270 && transform.position.x < m_Funnel.position.x))
            {
                if (StepsManager.Instance.StepTwoNum[1])
                {
                    StepsManager.Instance.StepTwoNum[2] = true;
                    StepsManager.Instance.SetStepTwo(2);
                    m_Water.SetActive(false);
                }
            }
        }

        towardPos = transform.position - lastPos; //两帧间向量差  
        speed = towardPos.magnitude / Time.deltaTime; // 距离/时间 
        lastPos = transform.position; //设置lastPosition
        m_WaterAnimator.SetFloat("speed", speed);
    }
}
